<template>
  <div class="advance-management-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <a-tabs v-model:activeKey="activeKey" @change="changeTabHandle">
        <a-tab-pane key="0" :tab="`预报(${pageStat['0']})`"></a-tab-pane>
        <a-tab-pane key="1" :tab="`已取消预报(${pageStat['1']})`"></a-tab-pane>
      </a-tabs>
      <super-table
        :height="tableHeight"
        ref="tableRef"
        :activeKey="activeKey"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
      >
        <template #tool>
          <a-button type="primary" @click="downloadLabelHandle(undefined, 1)"> 合并下载标签 </a-button>
        </template>
        <template #driverUserId="{ row }">
          <a-button type="link" v-if="row.shippingMethod === 0"> 查看 </a-button>
        </template>
        <template #status="{ row }">
          <a-tag v-if="row.status === 1" color="#f50"> 已收货 </a-tag>
          <a-tag v-if="row.status === 0" color="#2db7f5"> 已下单 </a-tag>
          <a-tag v-if="row.status === 2" color="#87d068"> 已入库 </a-tag>
        </template>
        <template #action="{ row }">
          <a-button type="link" @click="showHandle(row)">查看</a-button>
          <a-button v-if="activeKey === '0'" type="link" @click="editHandle(row)">编辑</a-button>
          <a-button v-if="activeKey === '0'" type="link" danger @click="cancelHandle(row)">取消预报</a-button>
          <a-button v-if="activeKey === '0'" type="link" @click="printLabelHandle(row)">打印</a-button>
          <a-button v-if="activeKey === '0'" type="link" @click="downloadLabelHandle(row, undefined)">下载</a-button>
        </template>
      </super-table>
    </div>
    <!-- 抽屉 -->
    <a-drawer class="custom-drawer" v-model:visible="drawerOpts.visible" :title="drawerOpts.title" :closable="true" @close="getData" :width="drawerOpts.width" placement="right">
      <component v-model:visible="drawerOpts.visible" :is="drawerOpts.component" :type="drawerOpts.type" :pass-data="drawerOpts.passData" @submit="drawerSubmitHandle"></component>
    </a-drawer>
  </div>
</template>
<script lang="ts">
import Details from "./components/details/index.vue";
import CancelAdvance from "./components/cancelAdvance/index.vue";
export default {
  name: "ClientAdvanceManagement",
  components: {
    Details,
    CancelAdvance
  }
};
</script>
<script lang="ts" setup>
import { onActivated, onMounted } from "vue";
import TableHeightHook from "@/hook/tableHeightHook";
import ModalHook from "@/hook/modalHook";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import { searchItemList, tableColumn } from "./data";
const { tableHeight, loading } = TableHeightHook(80);
const { tableData, searchForm, drawerOpts, activeKey, pageStat, tableRef } = InitHook();
const { searchHandle, getData, editHandle, showHandle, downloadLabelHandle, printLabelHandle, cancelHandle, changeTabHandle } = OperationHook({
  searchForm,
  tableData,
  drawerOpts,
  loading,
  activeKey,
  pageStat,
  tableRef
});
const { drawerSubmitHandle } = ModalHook({
  drawerOpts,
  callBack: () => getData()
});
const init = () => {
  if (history.state.params) {
    searchForm.preOrderNoList = history.state.params.preOrderNoList;
  }
  searchHandle();
};
onMounted(() => {
  init();
});
onActivated(() => {
  init();
});
</script>
<style lang="stylus" scoped></style>
